package OperationSystem.day1205File;


import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;

public class Input_Stream {
    public static void main(String[] args) throws IOException {
        /*
        InputStream is=new FileInputStream("你好.txt");
        System.out.println(is);
        is.close();
        */

        try (InputStream is = new FileInputStream("你好.txt")) {


           /*
           //b的意思有两个： 1.下一个字节          2.标志把文件读完了\r\n是换行符，不是流的结尾
            long len = 0;
            while (true) {
                int b = is.read();
                if (b == -1) {
                    break;
                }
                len++;
            }*/


            byte[] buffer = new byte[1024];
            long len = 0;
            long count = 0;
            while (true) {
                count++;
                int read = is.read(buffer);//一次最多读入1024个字节长度，把读到的数据放到buffer数组中
                //返回的read，代表真正读了多少字节(有可能小于1024)
                if (read == -1) {
                    break;
                }
                len += read;

            }
            System.out.println("循环次数"+count);
            System.out.println("文件的大小为" + len);
        }
    }
}
